//----------------------------------*-C++-*----------------------------------//
/*!
 * \file   testMomentsIndex.cc
 * \author Jeremy Roberts
 * \date   Aug 31, 2011
 * \brief  MomentsIndex test.
 * \note   Copyright (C) 2011 Jeremy Roberts. 
 */
//---------------------------------------------------------------------------//
// $Rev:: 124                                           $:Rev of last commit
// $Author:: j.alyn.roberts@gmail.com                   $:Author of last commit
// $Date:: 2011-09-01 02:25:26 +0000 (Thu, 01 Sep 2011) $:Date of last commit
//---------------------------------------------------------------------------//

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>

#include "test/Testing.hh"

#include "angle/Definitions.hh"
#include "angle/MomentsIndex.hh"

#include "tran/Traits.hh"

#include "../utilities/DBC.hh"
#include "../utilities/SP.hh"

using namespace std;
using namespace slabtran;
using namespace util;

// Test declarations.
int test1d_m_index();
int test2d_m_index();
int test3d_m_index();

int main(int argc, char *argv[])
{
  Require(argc==2);
  int test = atoi(argv[1]);
  cout << " ------ testMomentsIndex ------ " << endl;
  int test_value = 0;
  int number_of_tests = 4;

  if (test ==  1 || test == number_of_tests) test_value += test1d_m_index();
  if (test ==  2 || test == number_of_tests) test_value += test2d_m_index();
  if (test ==  3 || test == number_of_tests) test_value += test3d_m_index();

  if (test > number_of_tests || test < 1) cout << " test " << test
      << " not available. " << endl;
  if (test_value) cout << " failed with value = " << test_value << endl;
  else
    cout << " passed." << endl;
  return test_value;
  return 0;
}

int test1d_m_index()
{
  int legendre_order = 3;
  MomentsIndex<_1D> m(legendre_order);
  for (int l = 0; l <= legendre_order; l++)
  {
    const std::vector<int> &m_index = m.m_index(l);
    TEST(m_index.size() == 1);
    TEST(m_index[0] == 0);
  }
  cout << " ... passed 1d MomentsIndex::m_index test. " << endl;
  return 0;
}

int test2d_m_index()
{
  int legendre_order = 3;
  // set reference
  int m_ref[] = {0,-1,1,-2,-1,1,2,-3,-2,-1,1,2,3};
  MomentsIndex<_2D> mi(legendre_order);
  int j = 0;
  for (int l = 0; l <= legendre_order; l++)
  {
    const std::vector<int> &m_index = mi.m_index(l);
    if (l == 0) TEST(m_index.size() == 1    );
    if (l != 0) TEST(m_index.size() == 2 * l);
    for (int i = 0; i < m_index.size(); i++)
      TEST(m_index[i] == m_ref[j++]);
  }
  TEST(j == 13);
  cout << " ... passed 2d MomentsIndex::m_index test. " << endl;
  return 0;
}

int test3d_m_index()
{
  int legendre_order = 3;
  // set reference
  int m_ref[] = {0,-1,0,1,-2,-1,0,1,2,-3,-2,-1,0,1,2,3};
  MomentsIndex<_3D> mi(legendre_order);
  int j = 0;
  for (int l = 0; l <= legendre_order; l++)
  {
    const std::vector<int> &m_index = mi.m_index(l);
    TEST(m_index.size() == 2 * l + 1);
    for (int i = 0; i < m_index.size(); i++)
      TEST(m_index[i] == m_ref[j++]);
  }
  TEST(j == 16);
  cout << " ... passed 3d MomentsIndex::m_index test. " << endl;
  return 0;
}

//---------------------------------------------------------------------------//
//              end of testMomentsIndex.cc
//---------------------------------------------------------------------------//
